import Vue from 'vue'

Vue.directive('all-disabled',  (el, binding) => {

    const inputs = Array.from(el.querySelectorAll('input'))
    const selects = Array.from(el.querySelectorAll('selects'))
    const textareas = Array.from(el.querySelectorAll('textarea'))
    const formItems = inputs.concat(selects).concat(textareas)
    if (binding.value) {
      formItems.forEach((item) => {
        item.setAttribute('disabled','disabled')
        // element-ui会在父div上加这个类
        item.parentNode.classList.add('is-disabled')
      })
    }else {
      formItems.forEach((item) => {
        item.removeAttribute('disabled')
        item.parentNode.classList.remove('is-disabled')
      })
    }
  }
)

